<template>
  <div>
    <table-paging
      :table-list="tableList"
      :table-column="tableColumn"
      :table-paging="tablePaging"
      :table-total="tableTotal"
      :table-btn-width="80"
      @pagingChange="handlePaginChange"
    />
  </div>
</template>

<script>
import { fetchBbsRewardFindPage, fetchBbsRewardDelete } from '@/api/basicinfo/bbs/reward'
import { TablePaging } from '@/components'
import { searchFormItem, rewardTableColumn as tableColumn } from './config'

export default {
  name: 'Reward',
  components: { TablePaging },
  props: {
    bbsTopicId: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      searchFormItem,
      searchFormData: {},

      tableList: [],
      tableColumn: tableColumn(this.handleDelete),
      tableTotal: 0,
      tablePaging: {
        page: 1,
        pagesize: 10
      }
    }
  },
  created() {
    this.searchFormData = {
      bbsTopicId: this.bbsTopicId
    }
    this.postFindPage()
  },
  methods: {

    handleDelete(e) { // 删除
      this.postDelete(e)
    },

    handlePaginChange(pageInfo) { // 分页改变
      this.tablePaging = pageInfo
      this.postFindPage()
    },

    postFindPage() { // 查询数据
      fetchBbsRewardFindPage({ ...this.searchFormData, ...this.tablePaging })
        .then((res) => {
          const { records, current, size, total } = res
          this.tableList = records
          this.tablePaging = {
            page: current,
            pagesize: size
          }
          this.tableTotal = total
        })
    },

    postDelete(id) { // 删除
      fetchBbsRewardDelete({ id }).then(() => {
        this.$message.success('删除成功')
        this.postFindPage()
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
